import React, { Component } from 'react'
import '../css/phoneregister.css'
import { userRegister } from '../request/api'

export default class Login extends Component {
    constructor(){
        super()
        this.state={
            user:{
                phone:'',
                nickname:'',
                password:''
            }
        }
    }
    render() {
        const {user}=this.state
        return (
                <div className='phoneregister'>
                <div className='rigtitle'>
                    <div className='rrrgt' onClick={()=>this.props.history.go(-1)}>&gt;</div>
                    <div>注册</div>
                </div>
                <div className='phoneinmg'>
                    <img src="/xiaou.png" alt="" />
                </div>
                <div className="pinp">
                    <div className='ppbone'>
                        手机号 <input type="text" value={user.phone} onChange={(e)=>this.setState({user:{...user,phone:e.target.value}})} />
                    </div>
                    <div className='pyanzheng'>
                        昵称 <input type="text" value={user.nickname} onChange={(e)=>this.setState({user:{...user,nickname:e.target.value}})} />
                    </div>
                    <div className='pyanzheng'>
                        密码 <input type="password" value={user.password} onChange={(e)=>this.setState({user:{...user,password:e.target.value}})} />
                    </div>
                    <div className="denglu" onClick={()=>this.register()}>注册
                    </div>
                </div>
            </div>
        )
    }
    register(){
        const {user}=this.state
        userRegister(user).then(res=>{
            if(res.code===200){
                alert(res.msg)
                this.props.history.push('/phonelogin')
            }
        })
    }
}
